package site.util;

import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.StrutsStatics;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public abstract class Struts2Utils {

    public static ActionContext getActionContext() {
        return ActionContext.getContext();
    }

    public static HttpServletRequest getRequest() {
        return (HttpServletRequest) getActionContext().get(StrutsStatics.HTTP_REQUEST);
    }

    public static HttpServletResponse getResponse() {
        return (HttpServletResponse) ActionContext.getContext().get(StrutsStatics.HTTP_RESPONSE);
    }

    /**
     * Get Http Request Paramter.
     * @param paramName Parameter's Name.
     * @return Parameter's value.
     */
    public static String getParameter(String paramName) {
        return getRequest().getParameter(paramName);
    }

    /**
     * Get HttpSession. 
     * @param create Create or not.
     * @return HttpSession
     */
    public static HttpSession getSession(boolean create) {
        return getRequest().getSession(create);
    }

    /**
     * Get HttpSession. 
     * @return HttpSession
     */
    public static HttpSession getSession() {
        return getRequest().getSession();
    }

}
